"""
首页对象
"""
import allure
from selenium.webdriver.common.by import By
from base.base_page import BasePage, BaseProxy


class HomePage(BasePage):
    def __init__(self):
        super().__init__()
        self.update_close_btn = (By.ID, 'com.bjcsxq.chat.carfriend:id/dialog_close')
        self.me_btn = (By.ID, 'com.bjcsxq.chat.carfriend:id/tv_home_mine')


    def find_update_close_btn(self):
        return self.get_element(self.update_close_btn)

    def find_me_btn(self):
        return self.get_element(self.me_btn)


class HomeHandler:

    def __init__(self):
        self.home_page = HomePage()

    @allure.step(title='点击提示更新弹窗')
    def close_update_view(self):
        self.home_page.find_update_close_btn().click()

    @allure.step(title='点击我的页面按钮')
    def click_me_btn_to_me_page(self):
        self.home_page.find_me_btn().click()



class HomeProxy(BaseProxy):

    def __init__(self):
        super().__init__()
        self.home_handler = HomeHandler()

    @allure.step(title='流程:去我的页面')
    def go_me_page(self):
        """
        点击我的页面
        :return:
        """
        # 判断更新页面按钮是否存在
        if self.is_element_exist(self.home_handler.home_page.update_close_btn):
            self.home_handler.close_update_view()
        self.home_handler.click_me_btn_to_me_page()


if __name__ == '__main__':

    home_proxy = HomeProxy()
    home_proxy.go_me_page()